package com.jiandian.controller;

import com.jiandian.configration.OssConfig;
import com.jiandian.service.ApkService;
import com.jiandian.service.DictService;
import com.jiandian.util.BaseController;
import com.jiandian.util.BaseResult;
import com.jiandian.util.Constants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(value = "Apk", description = "游戏助手安装包")
@RestController
@RequestMapping("${jiandian.api.version}/Apk")
@CrossOrigin
public class ApkController extends BaseController {

    @Autowired
    private ApkService service;
    @Autowired
    private OssConfig ossConfig;

    @Autowired
    private DictService dictService;

    @ApiOperation(value = "获得游戏助手apk下载地址")
    @GetMapping(value = "")
    public BaseResult listApk(){
        String apkUrl = service.getApkUrl(ossConfig.getBucketName());
        return sendResult(Constants.RESPONSE_CODE_200,Constants.RESPONSE_MESSAGE_200,apkUrl);
    }
    @ApiOperation(value = "手动更新游戏助手apkUrl")
    @GetMapping(value = "/sync")
    public BaseResult syncSelfApkUrl(){
        service.syncSelfApkUrl(ossConfig.getBucketName());
        return sendResult(Constants.RESPONSE_CODE_200,Constants.RESPONSE_MESSAGE_200,"");
    }
}
